﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//buddy
using Zeta;
using Zeta.Common;
using Zeta.CommonBot;
using Zeta.Common.Plugins;
using Zeta.Internals;
using Zeta.Internals.Actors;
using Zeta.Internals.Service;

namespace MyBuddy.Local
{
    public class BuddyLeaderPlugin : IPlugin
    {
        Vector3 LastPosition { get; set; }
        DateTime LastPostionCheck { get; set; }

        public string Author
        {
            get { return "xsol"; }
        }

        public string Description
        {
            get { return "Leaves info for a follower to track."; }
        }

        public System.Windows.Window DisplayWindow
        {
            get { return null; }
        }

        public string Name
        {
            get { return "MyBuddy.Leader"; }
        }

        public void OnDisabled()
        {

        }

        public void OnEnabled()
        {
            if (null != ZetaDia.Me)
            {
                LastPosition = ZetaDia.Me.Position;
                LastPostionCheck = DateTime.Now;
            }
        }

        public void OnInitialize()
        {
            if(null != ZetaDia.Me)
            {
                LastPosition = ZetaDia.Me.Position;
                LastPostionCheck = DateTime.Now;
            }
        }

        public void OnPulse()
        {
            if (DateTime.Now.Subtract(LastPostionCheck).TotalMilliseconds > 250)
            {
                if (ZetaDia.Me.Position.Distance(LastPosition) > 8)
                {
                    LastPosition = ZetaDia.Me.Position;
                    DBFileMonitor.GLOBAL.UpdateLeaderLocation();
                }
            }
        }

        public void OnShutdown()
        {

        }

        public Version Version
        {
            get { return new Version(0, 0, 1); }
        }

        public bool Equals(IPlugin other)
        {
            return (this.Name == other.Name && this.Version == other.Version) ? true : false;
        }
    }
}
